function $(id){
    return document.getElementById(id);
}
window.onload=function(){
    /**
     * 轮播图
     */
    show();
    /**
     * 搜索栏JSON数据
     */
    $('gosearch').onclick=function(){
        var srcInfo=$('wsearch').value;
        var str="{" + "\"" + "value" + "\"" + ":" + "\"" + srcInfo + "\"" + "}";
        var stu=JSON.parse(str);
    }

    //左侧边栏
    $('open').onclick=function(){
        $("mySidenav").style.width="250px";
        // $("leftmain").style.marginLeft="250px";
        // document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
    }

    $('close').onclick=function(){
        $("mySidenav").style.width="0";
        $("leftmain").style.marginLeft="0";
        // document.body.style.backgroundColor = "white";
    }

    /**
     * 鼠标事件
     */
    $("cart").onmouseover=function(){
        this.style.cursor="pointer";
    }
    $("cart").onclick=function(){

        // console.log(111);
    }
}


/**
 * 轮播图
 */
var imgs=["../static/images/lunhuantu1.jpg",
    "../static/images/lunhuantu2.jpg",
    "../static/images/lunhuantu3.jpg",
    "../static/images/lunhuantu4.jpg"];
var i=1;
var timer;
/**
* show实现了视觉效果
*/
function show(index){
    if(index){
        i=index-1;
        clearTimeout(timer);
    }
    $('img').src=imgs[i];
    //将所有active样式删除
    document.querySelectorAll('span').forEach(function(item){
        item.classList.remove('active');
    })
    //为现在的页码添加样式
    document.querySelector('#carousel span:nth-child('+(i+1)+')').classList.add('active');
    i++;
    if(i>3){
        i=0;
    }
    timer=setTimeout(show,3000);
}
